package com.kuang.dao.impl;

import com.kuang.dao.DepartmentDao;
import com.kuang.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class DepartmentDaoImpl implements DepartmentDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    /**
     * 获取 所有部门
     * @return
     */
    @Override
    public Collection<Department> getDeparments() {
        String sql = "select * from department";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Department.class));
    }

    /**
     * 获取 根据id获取部门
     * @param id
     * @return
     */
    @Override
    public Department getDepartmentById(Integer id) {
        String sql = "select * from department where id=?";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Department.class), id);
    }
}
